<template>
  <el-form :inline="true" :model="formInline" class="form-inline">
    <el-row class="row">
      <el-form-item label="备件名称：">
        <el-input v-model="formInline.sparePartName" placeholder="--请输入--" />
      </el-form-item>
      <el-form-item label="所属系统：">
        <el-select
          v-model="formInline.system"
          placeholder="--请选择--"
          clearable
        >
          <el-option
            v-for="item in props.system"
            :key="item.code"
            :label="item.value"
            :value="item.code"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="入库时间：">
        <el-date-picker
          v-model="time"
          type="datetimerange"
          range-separator="~"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          value-format="YYYY-MM-DD HH:mm:ss"
          clearable
          @change="change"
          style="100%"
        />
      </el-form-item>
      <el-form-item class="btns">
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="success" @click="onClear">清空</el-button>
      </el-form-item>
    </el-row>
  </el-form>
</template>

<script setup>
import { reactive, defineEmits, ref, defineProps } from 'vue'

const props = defineProps({
  system: {
    type: Object,
    default: () => {}
  }
})
const formInline = reactive({
  sparePartName: '',
  system: '',
  endTime: '',
  startTime: ''
})
const time = ref()
const emits = defineEmits(['onSearch'])
const Code = ref()
const onSubmit = () => {
  emits('onSearch', formInline)
}

const change = (res) => {
  if (res) {
    formInline.startTime = res[0]
    formInline.endTime = res[1]
  } else {
    formInline.startTime = ''
    formInline.endTime = ''
  }
}
const onClear = () => {
  formInline.sparePartName = ''
  formInline.system = ''
  formInline.endTime = ''
  formInline.startTime = ''
  time.value = ''
  emits('onSearch', formInline)
}
</script>

<style lang="scss" scoped>
.form-inline {
  width: 100%;
  position: relative;
  display: flex;
  column-gap: 20px;
  // padding-bottom: 15px;
  .row {
    position: relative;
    width: 100%;
    .btns {
      position: absolute;
      right: 0;
      top: 0px;
      margin-right: 0px !important;
    }
  }
}
:deep(.el-form-item) {
  margin-right: 20px !important;
}
:deep(.el-form-item:nth-child(3)) {
  width: 525px;
}
:deep(.el-form-item__content) {
  width: 100%;
}
:deep(.el-date-editor--datetimerange) {
  width: 100% !important;
  opacity: 1;
  .el-range-separator {
    line-height: 31px;
  }
}
:deep(.el-input__inner) {
  width: 247px;
  opacity: 1;
}
</style>
